//
//  TabbarController.m
//  框架
//
//  Created by 刘明 on 16/3/21.
//  Copyright © 2016年 LM. All rights reserved.
//

#import "TabbarController.h"
#import "HomeViewController.h"
#import "TOCircleListViewController.h"
#import "TOschoolViewController.h"

#import "MeViewController.h"
#import "NavigationController.h"
#import "TabBar.h"
//中间按钮M
#import "TZComposeController.h"

@interface TabbarController ()<UITabBarDelegate,TabBarDelegate>
@property(weak,nonatomic)TabBar *tab;
@end
@implementation TabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加主页控制器
    HomeViewController * homeVC = [[HomeViewController alloc]init];
    [self addChildVC:homeVC andTitle:@"首页" andImage:@"tabbar_home" andSelectedImage:@"tabbar_home_selected"];
    
    //添加圈子控制器
    TOCircleListViewController * circleVC = [[TOCircleListViewController alloc] init];
    [self addChildVC:circleVC andTitle:@"圈子动态" andImage:@"tabbar_home" andSelectedImage:@"tabbar_home_selected"];
    
    //添加校园活动控制器
    TOSchoolViewController * schoolVC =[[TOSchoolViewController alloc] init];
    [self addChildVC:schoolVC andTitle:@"校园活动" andImage:@"tabbar_home" andSelectedImage:@"tabbar_home_selected"];
    
    //添加我的控制器
    MeViewController * focusListVC = [[MeViewController alloc] init];
    [self addChildVC:focusListVC andTitle:@"我的" andImage:@"tabbar_home" andSelectedImage:@"tabbar_home_selected"];
    
    
    TabBar *tab =  [[TabBar alloc]init];
    tab.Delegate = self;
    tab.translucent = NO;
    //添加自定义tabbar
    [self setValue:tab forKeyPath:@"tabBar"];
    self.tab =tab;
    
}



#pragma mark -添加控制器
/**
 *  添加一个控制器
 *
 *  @param childVc       传入的控制器
 *  @param title         传入的title
 *  @param image         非选中时的图片
 *  @param selectedImage 选中时的图片
 */
-(void)addChildVC:(UIViewController * )childVc andTitle:(NSString* )title andImage:(NSString *)image andSelectedImage:(NSString *)selectedImage
{
    
    //设置tabbar的文字
    childVc.title = title;
    //设置默认图片
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.navigationItem.title = title;
    
    //设置tabBarItem的普通文字颜色
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    [childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    //设置tabBarItem的选中文字颜色
    NSMutableDictionary *SelectextAttrs = [NSMutableDictionary dictionary];
    SelectextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [childVc.tabBarItem setTitleTextAttributes:SelectextAttrs forState:UIControlStateSelected];
    //设置选中图片
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //创建一个NavigationController
    NavigationController * nav = [[NavigationController alloc]initWithRootViewController:childVc];
    
    [self addChildViewController:nav];
}


//加号按钮代理方法
-(void)taBarDidClickPlusButton:(TabBar *)tabBar
{
    //弹出发微博控制器
    TZComposeController *compose = [[TZComposeController alloc]init];
    NavigationController *nav = [[NavigationController alloc]initWithRootViewController:compose];
    [self presentViewController:nav animated:YES completion:^{
        
    }];
    
    
}



@end
